package weather;

import client.WeatherWSLocator;
import client.WeatherWSSoap_PortType;

import java.util.Scanner;

public class ServiceClient {
    public static void main(String[] args) {
        try {
            WeatherWSLocator locator = new WeatherWSLocator();

            WeatherWSSoap_PortType port = locator.getWeatherWSSoap(new java.net.URL("http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl"));
            // 选择目标城市
            String[] supportCities = port.getSupportCityString("重庆");
            System.out.println("---- - - 重庆天气预报系统- - ----");
            System.out.println("可供选择的城市信息如下：");
            for (String city : supportCities) {
                String res = city.split(",")[0];
                System.out.print(res+" ");
            }
            System.out.println("\n");
            System.out.println("请输入城市名称：");
            Scanner sc = new Scanner(System.in);
            String target_city = sc.next();
            String[] weatherData = port.getWeather(target_city, "");
            System.out.println(target_city+"的天气预报信息如下：");
            for (String data : weatherData) {
                System.out.println(data);
            }

        } catch (Exception e) {
            e.printStackTrace();
            // 处理异常，例如记录日志或显示错误消息
        }
    }
}
